import Vue from "vue";
import Vuex from 'vuex'
//使用vuex
Vue.use(Vuex)

const m1 = {
  //解决命名空间问题
  namespaced: true,
  actions:{
    fetchChartData({ commit }) {
      return axios.get('/static/geojson/npp/2000.json').then(res => {
        commit('SET_CHART_DATA', res.data);
      });
    }
  },
  mutations:{
    SET_CHART_DATA(state, data) {
      state.chartData = data;
    }
  },
  state:{
    chartData: [] // 初始数据
  },
  getters:{
    getChartData: state => state.chartData
  }
}

//创建并暴露store
export default new Vuex.Store({
  //vuex里的配置项
  actions,
  mutations,
  state,
  getters,

  //vuex模块化
  modules:{
    m1,
  }
})